/**
 导航栏
 **/
(function(vc) {
    let DEFAULT_PAGE = 1;
    let DEFAULT_ROW = 10;
    var vm = new Vue({
        el: '#header',
        data: {
            headerInfo: {
                platformName: '',
                classes: [],
                informations: [],
                prodClasses: [],
                total:0,
                records:0
            },
            userInfo: {
                storeTypeCd: "",
                name: "",
                tel: "",
                levelCd: "",
                userId: "" ,
                cartProducts:[]
            },
            logo: '',
            userName: "",
            searchKey: '',
        },
        _initEvent: function () {
        },
        mounted: function() {
            this._loadInformations();
            let _getUserInfo = vc.getData('/nav/getUserInfo')
            if(_getUserInfo) {
                this.getUserInfo();
            }
        },
        methods: {
            //锚点跳转
            goAnchor(selector) {/*参数selector是id选择器（#anchor14）*/
                document.querySelector(selector).scrollIntoView({
                    behavior: "smooth"
                });
            },
            _loadInformations: function() {
                let _that = this;
                let param = {
                    params: {
                        page: 1,
                        row: 100
                    }
                };
                //发送get请求
                vc.http.apiGet('/system.initPlatformData',
                    param,
                    function(json, res) {
                        let _homePageInfo = JSON.parse(json);
                        _that.headerInfo.total = _homePageInfo.total;
                        _that.headerInfo.records = _homePageInfo.records;
                        _that.headerInfo.informations = _homePageInfo.data.platformInformation;
                        _that.headerInfo.prodClasses = _homePageInfo.data.platformProductClass;
                        _that.headerInfo.platformName = _homePageInfo.data.platformName;
                    },
                    function(errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            getUserInfo: function() {
                //获取用户名
                let param = {
                    msg: '123',
                };
                //发送get请求
                vc.http.apiGet('/user.getUserInfo',
                    param,
                    function(json, res) {
                        if (res.status == 200) {
                            var tmpUserInfo = JSON.parse(json);
                            vm.userInfo = tmpUserInfo;
                            //加个水印
                            if (tmpUserInfo.watermark == 'true') {
                                vc.watermark({ watermark_txt: vc.i18n('systemName') + ":" + tmpUserInfo.name });
                            }
                        }else{
                            console.log('请求失败处理*************************');
                        }
                    },
                    function() {
                        console.log('请求失败处理');
                    }
                );
            },
            logout: function() {
                let param = {
                    msg: 123
                };
                //发送get请求
                vc.http.apiPost('/login.userLogout',
                    JSON.stringify(param), {
                        emulateJSON: true
                    },
                    function(json, res) {
                        if (res.status == 200) {
                            // 清除本地sessionStorage存储的tab
                            vc.clearTabToLocal();
                            vc.jumpToPage("/page.html");
                            return;
                        }
                    },
                    function() {
                        console.log('请求失败处理');
                    }
                );
            },
            _jumpToPage: function (_classId) {
                vc.jumpToPage("/page.html#/pages/plateform/product?hktId=" + _classId);
            },
            _jumpProductPage: function () {
                vc.jumpToPage("/page.html#/pages/plateform/product?searchKey=" + vm.searchKey);
            }
        }
    });
    // vm.getUserInfo();
})(window.vc);
